import socket
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('127.0.0.1',8001))
st="请求连接！"
s.sendall(st.encode())
s1=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s1.bind(('127.0.0.1',8002))
s1.listen()
conn,address=s1.accept()
public_key_get=conn.recv(1024)
public_key = RSA.importKey(public_key_get)
cipher = PKCS1_OAEP.new(public_key)
print('服务器发来了公钥：'+ str(public_key))

s2=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s2.connect(('127.0.0.1',8001))
file=open(r'C:\Users\曾令杰\Desktop\2.txt','r+',encoding='utf-8')
data=file.read()
c_data = cipher.encrypt(data.encode())
s2.sendall(c_data)
s2.close()





